#pragma once
#include "gamescene.hpp"

namespace VN{
    class SaveName:public InputBox{
        protected:
        void OnTextChanged();
        void OnInputFinish();
        public:
        SaveName(Window* window,SDL_Rect r,const char* alert);
    };
    class SkipButton:public TextButton{
        protected:
        void OnClick(int x,int y,unsigned char key);
        void OnDoubleClick(int x,int y,unsigned char key);
        GameScene* g;
        public:
        SkipButton(SDL_Point p,GameScene*,const char* text,SDL_Color text_color);
        ~SkipButton();
    };
    class GoBack:public TextButton{
        protected:
        void OnClick(int x,int y,unsigned char key);
        void OnDoubleClick(int x,int y,unsigned char key);
        GameScene* g;
        public:
        GoBack(SDL_Point p,GameScene*,const char* text,SDL_Color text_color);
        ~GoBack();
    };
    class EnterSaveButton:public TextButton{
        protected:
        void OnClick(int x,int y,unsigned char key);
        void OnDoubleClick(int x,int y,unsigned char key);
        GameScene* g;
        public:
        EnterSaveButton(SDL_Point p,GameScene*,const char* text,SDL_Color text_color);
        ~EnterSaveButton();
    };
    class QuitButton:public TextButton{
        protected:
        void OnClick(int x,int y,unsigned char key);
        void OnDoubleClick(int x,int y,unsigned char key);
        public:
        QuitButton(SDL_Point p,Window* w,const char* text,SDL_Color text_color);
        ~QuitButton();
    };
    class EnterCGButton:public TextButton{
        protected:
        void OnClick(int x,int y,unsigned char key);
        void OnDoubleClick(int x,int y,unsigned char key);
        GameScene* g;
        public:
        EnterCGButton(SDL_Point p,GameScene*,const char* text,SDL_Color text_color);
        ~EnterCGButton();
    };
    class ConfirmSaveButton:public TextButton{
        protected:
        void OnClick(int x,int y,unsigned char key);
        void OnDoubleClick(int x,int y,unsigned char key);
        GameScene* g;
        public:
        ConfirmSaveButton(SDL_Point p,GameScene*,const char* text,SDL_Color text_color);
        ~ConfirmSaveButton();
    };
    class StartGameButton:public TextButton{
        protected:
        void OnClick(int x,int y,unsigned char key);
        void OnDoubleClick(int x,int y,unsigned char key);
        GameScene* g;
        public:
        StartGameButton(SDL_Point p,GameScene*,const char* text,SDL_Color text_color);
        ~StartGameButton();
    };
    class AutoPlayButton:public TextButton{
        protected:
        void OnClick(int x,int y,unsigned char key);
        void OnDoubleClick(int x,int y,unsigned char key);
        GameScene* g;
        public:
        AutoPlayButton(SDL_Point p,GameScene*,const char* text,SDL_Color text_color);
        ~AutoPlayButton();
        void _draw();
    };
    class OpenBackLogButton:public TextButton{
        protected:
        void OnClick(int x,int y,unsigned char key);
        void OnDoubleClick(int x,int y,unsigned char key);
        GameScene* g;
        public:
        OpenBackLogButton(SDL_Point p,GameScene*,const char* text,SDL_Color text_color);
        ~OpenBackLogButton();
    };
    class LoadSaveButton:public TextButton{
        protected:
        void OnClick(int x,int y,unsigned char key);
        void OnDoubleClick(int x,int y,unsigned char key);
        GameScene* g;
        public:
        LoadSaveButton(SDL_Point p,GameScene*,const char* text,SDL_Color text_color);
        ~LoadSaveButton();
    };
    class AutoPlayNormalButton:public TextButton{
        protected:
        void OnClick(int x,int y,unsigned char key);
        void OnDoubleClick(int x,int y,unsigned char key);
        GameScene* g;
        public:
        AutoPlayNormalButton(SDL_Point p,GameScene*,const char* text,SDL_Color text_color);
        ~AutoPlayNormalButton();
        void _draw();
    };
    class AutoPlayFastButton:public TextButton{
        protected:
        void OnClick(int x,int y,unsigned char key);
        void OnDoubleClick(int x,int y,unsigned char key);
        GameScene* g;
        public:
        AutoPlayFastButton(SDL_Point p,GameScene*,const char* text,SDL_Color text_color);
        ~AutoPlayFastButton();
        void _draw();
    };
    class LanguageSelect:public DropList{
        protected:
        void OnSelect();
        GameScene* g;
        public:
        LanguageSelect(GameScene* g,SDL_Rect& rect,initializer_list<string*> init={}
        ,int item_height=15,size_t max_item=6);
        ~LanguageSelect();
    };
    class ChooseProgress:public ProgressBar{
        protected:
        void OnChanged(double value);
        public:
        ChooseProgress(Window* w,SDL_Rect& r,double init=1.,SDL_Color back=Color::Black,
        SDL_Color front=Color::ManganeseBlue,int bound=3);
    };
    class EnterOptionButton:public TextButton{
        protected:
        void OnClick(int x,int y,unsigned char key);
        void OnDoubleClick(int x,int y,unsigned char key);
        GameScene* g;
        public:
        EnterOptionButton(SDL_Point p,GameScene* g,const char* text,SDL_Color text_color);
        ~EnterOptionButton();
    };
    class EnterMainButton:public TextButton{
        protected:
        void OnClick(int x,int y,unsigned char key);
        void OnDoubleClick(int x,int y,unsigned char key);
        GameScene* g;
        public:
        EnterMainButton(SDL_Point p,GameScene* g,const char* text,SDL_Color text_color);
        ~EnterMainButton();
    };
    class EffectBox:public CheckBox{
        protected:
        GameScene* g;
        void OnChanged();
        public:
        EffectBox(SDL_Point p,GameScene*);
        ~EffectBox();
    };
    class MusicBox:public CheckBox{
        protected:
        GameScene* g;
        void OnChanged();
        public:
        MusicBox(SDL_Point p,GameScene*);
        ~MusicBox();
    };
    class EffectBar:public TextureBar{
        protected:
        GameScene* g;
        void OnChanged(double value);
        public:
        EffectBar(SDL_Rect r,GameScene*,SDL_Texture* fg,SDL_Texture* bg);
        ~EffectBar();
    };
    class MusicBar:public TextureBar{
        protected:
        GameScene* g;
        void OnChanged(double value);
        public:
        MusicBar(SDL_Rect r,GameScene*,SDL_Texture* fg,SDL_Texture* bg);
        ~MusicBar();
    };
   class ChooseButton:public Control{
        protected:
        Logic logic;
        SDL_Texture* _t,*back;//back共享
        GameScene* g;
        public:
        SDL_Rect _rect;//给文本算的居中
        ChooseButton(SDL_Texture* b,GameScene*,const vector<TextMod>& text,Logic func);
        ~ChooseButton();
        void _release(int x,int y,int clicks,unsigned char key);
        void _draw();
    };

    //用于展示存档名和下拉信息(下拉信息在新增或读取存档时初始化)
    class SaveItem:public TableItem{
        protected:
        //仅引用 不管理
        GameScene* game;
        SaveObject* save;
        SDL_Texture* t,*name,*time;//用于绘制缩略图
        
        public:
        void Update(SaveObject* o);
        SaveItem(GameScene* g,SaveObject* s);
        ~SaveItem()override;
        void _click(BaseListView* list,int x,int y,unsigned char key);
        void _double_click(BaseListView* list,int x,int y,unsigned char key);
        void Draw(Renderer* render,ListState state,SDL_Rect& rect)override;
    };
    class CGItem:public ListItem{
        protected:
        GameScene* g;
        CGPack* state;
        public:
        void _click(BaseListView* list,int x,int y,unsigned char key);
        void _double_click(BaseListView* list,int x,int y,unsigned char key);
        CGItem(GameScene* game,CGPack* s);
        ~CGItem();
        void Draw(Renderer* render,ListState state,SDL_Rect& rect)override;
    };
    //根节点显示说话人 子节点显示具体文本（按行）
    class BackLogItem:public TextItem{
        SDL_Texture* name_t;//content_t用于缓存内容
        public:
        vector<pair<int,int>> info;
        SDL_Texture* content_t;
        BackLogItem(Window* w,vector<TextMod> name,const vector<TextMod> content);
        void Draw(Renderer* render,ListState state,SDL_Rect& rect)override;
        ~BackLogItem();
    };
    //backlog的子节点 存
    class LogTextItem:public TextItem{
        public:
        SDL_Rect src;
        SDL_Texture* content_t;//从BackLog引用，不管理
        LogTextItem(Window* win,int w,int h,int y,SDL_Texture* c);
        ~LogTextItem();
        void Draw(Renderer* render,ListState state,SDL_Rect& rect)override;
    };
    class MusicItem:public TextItem{
        public:
        GameScene* game;
        MusicItem(GameScene* g,const char* music,Font* f);
        ~MusicItem();
        void _click(BaseListView* list,int x,int y,unsigned char key);
        void _double_click(BaseListView* list,int x,int y,unsigned char key);
    };
    class CGList:public TableView{
        public:
        CGList(Window* window,SDL_Rect& rect,int spacex=2,int spacey=2,int item_w=16,int item_h=16,
        SDL_Color background=Color::Gray,SDL_Color select_color=Color::Blue,SDL_Color on_color=Color::SkyBlueGray,
        SDL_Color normal_scroll_color={0,0,0,120},SDL_Color on_scroll_color={0,0,0,220});
        void _draw_edge();
    };
}